export default {
    // name: "count-down",
    data: function () {
        return {
            countTime: 100,  //倒计时的时间(s)
            timer: null,
        }
    },
    template: `<div class="count-down">
            {{beauty(hour)}}:{{beauty(min)}}:{{beauty(sec)}}
        </div>`,
    methods: {
        beauty(num) {
            return num < 10 ? "0" + num : num;
        },
        countDownHandler() {
            clearInterval(this.timer);
            this.timer = setInterval(() => {
                this.countTime--;
            }, 1000)
        }
    },
    computed: {
        // 将倒计时的时间换算为天时分秒
        day: function () {
            return parseInt(this.countTime / (24 * 60 * 60));
        },
        hour: function () {
            // 总的时间 % 一天的时间 =>  不满一天的时间
            // 不满一天的时间 / 一小时
            return parseInt(this.countTime % (24 * 60 * 60) / (60 * 60))
        },
        min: function () {
            // 不满一小时 / 一分钟
            return parseInt(this.countTime % (60 * 60) / 60);
        },
        sec: function () {
            // 不满一小时 / 一分钟
            return this.countTime % 60;
        },
    },
    beforeCreate() {
        console.log("子组件count-down:beforeCreate");
    },
    created() {
        console.log("子组件count-down:created");
    },
    beforeMount() {
        console.log("子组件count-down:beforeMount");
    },
    mounted() {
        this.countDownHandler();
        console.log("子组件count-down:mounted", this);
    },
}